<?php
if ( defined('ABSPATH') )
	include_once ABSPATH . 'config.php';
else
    include_once '../config.php';

class Channel {
	
	var $id = "";
	var $ownerid = "";
	var $name = "";
	var $public = false;
	
	function Channel($id='')
	{
		$this->id = $id;
	}
	
   function Create($ownerid, $name) {
    	global $db;
    	
    	$rs = $db->query("insert into $db->channels (ownerid, name) values('$ownerid','".$db->escape($name)."')");
    	
    	if($rs)
    	{
    		$id = $db->insert_id;
    	}
    	
		return $id;
   }
		
   function Save() {
    	global $db;
    	
    	$rs = $db->query("update $db->channels set name='".$db->escape($this->name)."',public='$this->public' where id='$this->id'");

   }

   function Delete() {
    	global $db;
    	
    	$db->query("delete from $db->channels where id='$this->id'");
    	$db->query("delete from $db->cnxn_channels where channel_id='$this->id'");
    	
   }
   
   
   function Get() {
    	global $db;
    	$row = $db->get_row("select name, public from $db->channels where id='$this->id'",ARRAY_A);

    	if($row)
    	{
    		$this->ownerid=$row["ownerid"];
    		$this->name=$row["name"];    		
    		$this->public=$row["public"];
    	}
    		
    	return $row;
   }
   
}

class Channels {
	function Get($ownerid)
	{
		global $db;
		
		$rs = $db->get_results("select id,name, public from $db->channels where ownerid='$ownerid'",ARRAY_A);
		
		return $rs;
	}
}





?>